// ----------------------------------------
// Filename: Ready_Queue.h
// Description: The header file for a ready queue
// Author: Jon Maloney
// Date: 30-May-2012
//

#ifndef M_QUEUE_H
#define M_QUEUE_H

//************************************************************
//                    Include .h files
//************************************************************
#include "microRTOS.h"
#include "binary_Semaphore.h"
//************************************************************
//                    Include external references
//************************************************************

//************************************************************
//                    Define Statements
//************************************************************

//************************************************************
//                    Struct, Union, enum Statements
//************************************************************

// ----------------------------------------
// mQueue structure
typedef struct
{
	UINT8   	Head;
	UINT8		Tail;
	UINT8   	NbItem;
	UINT8   	volatile ItemNb;
	UINT8		ItemSize;
	ptr_8   	Buffer;
	bsem_Handle q_Semaphore;
} queue_t;

typedef queue_t * m_QueueHandle; 

//************************************************************
//                    Global variables and constants
//************************************************************

//************************************************************
//                    Prototype Global Functions
//************************************************************

// ----------------------------------------
// mqueue_Create
// 
// Initialize the queue
// Input:
//   NbItem: 	the maximum number of items in the queue
//	 ItemSize:	the size of each item in the queue.
// Output:
//   m_QueueHandle a handle to the queue that has been created.
//		If null the queue could not be created.
// Conditions:
//  none

m_QueueHandle mqueue_Create(UINT8 NbItem, UINT8 ItemSize);

// ----------------------------------------
// mqueue_Delete
// 
// Deletes the queue
// Input:
//   mQueue 		is a queue handle (a pointer to a queue structure)
// Output:
//   none
// Conditions:
//  none
void mqueue_Delete(m_QueueHandle mQueue);

// ----------------------------------------
// mqueue_Put
// 
// Add an item to the next space available in the queue
// Input:
//   mQueue 		is a queue handle (a pointer to a queue structure)
//   ItemPtr: 		is the data to store in the queue
//	 delay:			The maximum time that the queue will wait for data to become available (0 = wait forever)
// Output:
//   TRUE if data is properly added to the queue
//	 FALSE if data could not be placed in queue
//		Either queue is full, 
//		There is no room on the heap to place the item,
//		queue handle is NULL.
// Conditions:
//   

BOOL mqueue_Put(m_QueueHandle mQueue, void * ItemPtr, kernelTickType delay); 

// ----------------------------------------
// mqueue_Get
// 
// Remove the next item from the queue
// Input:
//   mQueue: 	is a queue handle (a pointer to a queue structure)
//	 ItemPtr:	a pointer to the location that the next item in the queue will be placed.
//	 delay:		The maximum time that the queue will wait for data to become available (0 = wait forever)
// Output:
//   TRUE if the operation was successful and the data is valid
//	 False if the get operation failed.
//		either the queue is empty or
//		the queue handle is NULL
// Conditions:
//   none

BOOL mqueue_Get(m_QueueHandle mQueue, void * ItemPtr, kernelTickType delay); 

// ----------------------------------------
// mqueue_IsSpaceAvailable
// 
// Determines if there is room left in the queue
//	
// Input:
//  mQueue is a queue handle (a pointer to a queue structure)
// Output:
// 	TRUE if there is room left in the queue
//	FALSE if the queue is full or
//		  if the queue handle is NULL
// Conditions:
//   none
inline BOOL mqueue_IsSpaceAvailable(m_QueueHandle mQueue);

// ----------------------------------------
// mqueue_IsEmpty
// 
// Determines if the queue is empty
// Input:
//  mQueue is a queue handle (a pointer to a queue structure)
// Output:
// 	TRUE if the queue is empty
//	FALSE if the queue is not empty
//		  if the queue handle is NULL
// Conditions:
//   none
inline BOOL mqueue_IsEmpty(m_QueueHandle mQueue);



#endif
